package com.ruoyi.quartz.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.page.TableSupport;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.exception.job.TaskException;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.quartz.service.IOrderService;
import com.ruoyi.quartz.service.IUpdateService;
import com.ruoyi.system.domain.DTO.OrderJobDto;
import com.ruoyi.system.domain.DTO.SysOrderDto;
import com.ruoyi.system.domain.DTO.UpdateDto;
import com.ruoyi.system.domain.vo.InstantBookingVo;
import com.ruoyi.system.domain.vo.OrderLogVo;
import com.ruoyi.system.domain.vo.UpdateVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

/**
 * 部门信息
 * 
 */
@Controller
@RequestMapping("/business/update")
public class UpdateJobController extends BaseController
{
    private String prefix = "business/update";

    @Autowired
    private IUpdateService iUpdateService;

    @RequiresPermissions("business:update:view")
    @GetMapping()
    public String dept() {
        return prefix + "/update";
    }

    @RequiresPermissions("business:update:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(UpdateDto updateDto) {
        List<UpdateVo> updateVoList = new ArrayList<UpdateVo>();

        startPage();
        updateVoList = iUpdateService.list(updateDto);
        return getDataTable(updateVoList);
    }

    @RequiresPermissions("business:update:list")
    @GetMapping("/edit/{id}")
    @ResponseBody
    public AjaxResult update(@PathVariable("id") String id) {
        if(id == null){
            return AjaxResult.error("缺少必传参数");
        }
        if(!id.contains("-")){
            return AjaxResult.error("缺少修改密码");
        }
        String mima = id.substring(id.indexOf("-")+1,id.length());
        if(!mima.equals("123456")){
            return AjaxResult.error("密码错误");
        }
        UpdateDto updateDto = new UpdateDto();
        updateDto.setId(Long.parseLong(id.substring(0,id.indexOf("-"))));
        return iUpdateService.update(updateDto);
    }

    @RequiresPermissions("business:update:list")
    @GetMapping("/edit2/{id}")
    @ResponseBody
    public AjaxResult update2(@PathVariable("id") String id) {
        if(id == null){
            return AjaxResult.error("缺少必传参数");
        }
        if(!id.contains("-")){
            return AjaxResult.error("缺少修改密码");
        }
        String mima = id.substring(id.indexOf("-")+1,id.length());
        if(!mima.equals("123456")){
            return AjaxResult.error("密码错误");
        }
        UpdateDto updateDto = new UpdateDto();
        updateDto.setId(Long.parseLong(id.substring(0,id.indexOf("-"))));
        return iUpdateService.update2(updateDto);
    }

}
